﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/Admin/_AdminLayout.cshtml";
}
<script src="~/Content/CSS/admin/datetimepicker/jquery-1.9.1.js"></script>
<link href="~/Content/CSS/admin/datetimepicker/jquery-ui-1.10.3.custom.css" rel="stylesheet" />
<script src="~/Content/CSS/admin/datetimepicker/jquery-ui-1.10.3.custom.js"></script>
@using PagedList.Mvc;
@using PagedList;
<script>
    $(function () {
        $("#from").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            numberOfMonths: 1,
            dateFormat: 'dd/mm/yy',
            onClose: function (selectedDate) {
                $("#to").datepicker("option", "minDate", selectedDate);
            }
        });
        $("#to").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            dateFormat: 'dd/mm/yy',
            numberOfMonths: 1,
            onClose: function (selectedDate) {
                $("#from").datepicker("option", "maxDate", selectedDate);
            }
        });
        $("#indate").datepicker({
            defaultDate: "+1w",
            changeMonth: true,
            dateFormat: 'dd/mm/yy',
            numberOfMonths: 1,
            onClose: function (selectedDate) {
                $("#indate").datepicker("option", "maxDate", selectedDate);
            }
        });
    });
</script>
<div id="content" class="span10">
    <!-- content starts -->
    <div>
        <ul class="breadcrumb">
            <li>
                <a href="#">Home</a> <span class="divider">/</span>
            </li>
            <li>
                <a href="#">Danh sách đơn hàng</a>
            </li>
        </ul>
    </div>
    <div class="row-fluid sortable">
        <div class="box span12">
            <div class="box-content">
                <div class="row-fluid">
                    <div class="span12 form-inline">
                        @using (Html.BeginForm("Index", "AdminHoaDon", FormMethod.Get))
                        {
                            <div id="search-box" style="text-align: left">
                                <input type="radio" name="ynRadio" class="radioBtn" value="range" checked="checked" />
                                <label for="from">từ ngày</label>
                                <input type="text" id="from" name="from" value="@ViewBag.FromDate"/>
                                <label for="to">đến ngày</label>
                                <input type="text" id="to" name="to" value="@ViewBag.ToDate"/>
                                <input type="radio" name="ynRadio" class="radioBtn" value="theongay" />
                                <label for="from">Theo ngày</label>
                                <input type="text" id="indate" name="indate" value="@ViewBag.InDate" disabled/>
                                <input type="submit" value="Lọc" class="button4" />
                                <input type="submit" value="Nhập lại" class="button4" onclick="Reset()" />
                                <script>
                                    function Reset() {
                                        $("#indate").val("");
                                        $("#from").val("");
                                        $("#to").val("");
                                    }
                                    $(".radioBtn").click(function () {
                                        $("#in").attr("disabled", true);
                                        if ($("input[name=ynRadio]:checked").val() == "theongay") {
                                            $("#indate").attr("disabled", false);
                                            $("#from").attr("disabled", true);
                                            $("#to").attr("disabled", true);
                                        }
                                        if ($("input[name=ynRadio]:checked").val() == "range") {
                                            $("#indate").attr("disabled", true);
                                            $("#from").attr("disabled", false);
                                            $("#to").attr("disabled", false);
                                        }
                                    });
                                </script>
                            </div>
                        }
                    </div>

                </div>
                <div class="row-fluid">
                    <div style="float:right;margin-right:20px;">
                        Hiển thị 
               <select id="HienThi" style="width: 100px;">
                   <option value="5" @if (ViewBag.HienThi == 10)
                                     { @:selected="selected" 
                       }>5</option>
                   <option value="10" @if (ViewBag.HienThi == 10)
                                      { @:selected="selected" 
                       }>10</option>
                   <option value="15" @if (ViewBag.HienThi == 15)
                                      { @:selected="selected" 
                       }>15</option>
                   <option value="20" @if (ViewBag.HienThi == 20)
                                      { @:selected="selected" 
                       }>20</option>
                   <option value="50" @if (ViewBag.HienThi == 50)
                                      { @:selected="selected" 
                       }>50</option>
               </select>
                        Sắp xếp
              
               <select id="SapXep" style="width: 100px;">
                   <option value="8" @if (ViewBag.SapXep == 5)
                                     { @:selected="selected" 
                       }>Tất cả</option>
                   <option value="0" @if (ViewBag.SapXep == 0)
                                     { @:selected="selected" 
                       }>Chưa liên hệ</option>
                   <option value="1" @if (ViewBag.SapXep == 1)
                                     { @:selected="selected" 
                       }>Chưa giao hàng</option>
                   <option value="2" @if (ViewBag.SapXep == 2)
                                     { @:selected="selected" 
                       }>Ðã giao</option>
                    <option value="3" @if (ViewBag.SapXep == 3)
                                     { @:selected="selected" 
                       }>Hủy</option>
                   <option value="4" @if (ViewBag.SapXep == 4)
                                     { @:selected="selected" 
                       }>Mới nhất</option>
                   <option value="5" @if (ViewBag.SapXep == 5)
                                     { @:selected="selected" 
                       }>Cũ nhất</option>
                    <option value="6" @if (ViewBag.SapXep == 6)
                                     { @:selected="selected" 
                       }>Tổng tiền cao nhất</option>
                   <option value="7" @if (ViewBag.SapXep == 7)
                                     { @:selected="selected" 
                       }>Tổng tiền thấp nhất</option>
               </select>
                        <script>
                            $("#HienThi").change(function () {
                                var hienthi = $(this).val();
                                window.location.href = 'http://' + window.location.host + '/AdminHoaDon/?HienThi=' + hienthi + '&SapXep=@ViewBag.SapXep&from=@ViewBag.FromDate&to=@ViewBag.ToDate&indate=@ViewBag.Indate';

                            });
                            $("#SapXep").change(function () {
                                var sapxep = $(this).val();
                                @*window.location.href = 'http://' + window.location.host + '/AdminSanPham/DanhSach/?SapXep=' + sapxep + '&HienThi=' + @ViewBag.HienThi + '&currentFilter=@ViewBag.CurrentFilter' + '&IdDanhMuc=@ViewBag.DanhMuc' + '&IdThuongHieu=@ViewBag.ThuongHieu';*@
                                window.location.href = 'http://' + window.location.host + '/AdminHoaDon/?HienThi=@ViewBag.HienThi' + '&SapXep=' + sapxep + '&from=@ViewBag.FromDate&to=@ViewBag.ToDate&indate=@ViewBag.Indate';

                            });
                        </script>
                    </div>
                </div>

            </div>
            <div class="clearfix"></div>
            <table class="table table-striped table-bordered bootstrap-datatable datatable">
                <thead>
                    <tr>
                        <th>id</th>
                        <th>Ngày lập</th>
                        <th>Ðịa chỉ giao hàng</th>
                        <th>Số diện thoại</th>
                        <th>Tên khách hàng</th>
                        <th>Trạng thái</th>
                        <th>Tổng giá trị</th>
                        <th>Chi tiết</th>
                    </tr>
                </thead>
                <tbody>
                    @{PagedList<BabyToys.Models.HoaDon> hoadons = ViewBag.OnePageOfHoaDon;}
                    @foreach (var hoadon in hoadons)
                    {
                        <tr class="item_row" style="border-color: #F0F0F0; border-style: Solid; height: 40px;">
                            <td class="item_float">@hoadon.IdHoaDon</td>
                            <td class="item_float">

                                @{
                        DateTime date = new DateTime(2013, 9, 1, 0, 0, 0);
                        string NgayLap = String.Format("{0:d/M/yyyy HH:mm:ss}", @hoadon.NgayLapHD);
                                }
                                @NgayLap
                            </td>
                            <td class="item_float">@hoadon.DiaChiGiaoHang </td>
                            <td class="item_float">@hoadon.SoDienThoai</td>
                            <td class="item_float">@hoadon.TenNguoiNhan</td>
                            <td class="item_float">
                                <select id="@Html.Raw("TrangThai" + hoadon.IdHoaDon)" onchange="CapNhatTrangThai(@hoadon.IdHoaDon)"
                                    @Html.Raw(ViewBag.Xoa == true ? "" : "disabled=\"disabled\"")
                                    @Html.Raw(hoadon.TrangThai==4 ? "disabled=\"disabled\"" : "")
                                    >
                                    <option value="1" @if (hoadon.TrangThai == 1)
                                                      { @:selected="selected" 
                       }>Chưa liên hệ</option>
                                    <option value="2" @if (hoadon.TrangThai == 2)
                                                      { @:selected="selected" 
                       }>Chưa giao hàng</option>
                                    <option value="3" @if (hoadon.TrangThai == 3)
                                                      { @:selected="selected" 
                       }>Ðã giao hàng</option>
                                    <option value="4" @if (hoadon.TrangThai == 4)
                                                      { @:selected="selected" 
                       }>Hủy</option>
                                     
                                </select>
                                <script>
                                    function CapNhatTrangThai(id) {
                                        var x = confirm("Bạn có chắc muốn cập nhật trạng thái hóa đơn này?");
                                        if (x == true) {
                                            var ten = '#TrangThai' + id;
                                            var id = id;
                                            var trangthai = $(ten).val();
                                            var submitData = {
                                                id: id,
                                                trangthai: trangthai
                                            }
                                            //alert("ch?n: "+trangthai+","+id);
                                           $.post("/AdminHoaDon/CapNhatTrangThai/", { "id": id, "trangthai": trangthai },
                                                    function (data) {
                                                        var xacnhan = confirm("Cập Nhật Thành Công, bạn có muốn cập nhật lại danh sách?");
                                                        if (xacnhan == true) {
                                                            window.location.reload();
                                                        }
                                                    });
                                        } else {
                                            window.location.reload();
                                        }

                                    }
                                    function Reload() {
                                        alert("Cập nhật thành công");
                                    }
                                </script>

                            </td>
                            <td>@hoadon.TongGiaTri</td>
                            <td class="item_float">
                                <a href="~/AdminHoaDon/ChiTiet/?id=@hoadon.IdHoaDon">Xem chi tiết</a>
                            </td>
                        </tr>
                    }
                </tbody>
            </table>
            <div class="pagination pagination-centered">
                @Html.PagedListPager((IPagedList)ViewBag.OnePageOfHoaDon, page => Url.Action("Index", new { page, HienThi = ViewBag.HienThi, SapXep = ViewBag.SapXep, from = ViewBag.FromDate, to = ViewBag.ToDate, indate = ViewBag.Indate }), PagedListRenderOptions.OnlyShowFivePagesAtATime)
            </div>
        </div>
    </div>
</div>


